package com.achievement.controller;

import com.achievement.domain.dto.MagazineDTO;
import com.achievement.domain.entity.MagazineEntity;
import com.achievement.domain.param.MagazineParam;
import com.achievement.domain.vo.MagazineVO;
import com.achievement.service.IMagazineService;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 科研成果-期刊Controller
 */
@RestController
@RequestMapping("/achievement/magazine")
@Api(tags = "成果管理模块---期刊")
public class MagazineController extends BaseController {
    @Autowired
    private IMagazineService magazineService;

    /**
     * 查询科研成果-期刊列表
     */
    @PreAuthorize("@ss.hasPermi('system:magazine:list')")
    @ApiOperation(value = "列表检索", notes = "列表检索")
    @GetMapping("/list")
    public TableDataInfo list(MagazineParam dto) {
        startPage();
        List<MagazineVO> list = magazineService.selectByPage(dto);
        return getDataTable(list);
    }

    /**
     * 查询刊物论文集名称
     */
    @PreAuthorize("@ss.hasPermi('system:magazine:list')")
    @ApiOperation(value = "查询刊物论文集名称", notes = "查询刊物论文集名称")
    @GetMapping("/select")
    public TableDataInfo selectName(MagazineParam dto) {
        List<String> list = magazineService.select(dto);
        return getDataTable(list);
    }

    /**
     * 导出科研成果-期刊列表
     */
    @PreAuthorize("@ss.hasPermi('system:magazine:export')")
    @Log(title = "科研成果-期刊", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "期刊导出", notes = "期刊导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MagazineDTO dto) {
        List<MagazineEntity> list = magazineService.getListByConditions(dto);
        ExcelUtil<MagazineEntity> util = new ExcelUtil<>(MagazineEntity.class);
        util.exportExcel(response, list, "科研成果-期刊数据");
    }

    /**
     * 获取科研成果-期刊详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:magazine:query')")
    @ApiOperation(value = "获取期刊详细信息", notes = "获取期刊详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(magazineService.getInfoById(id));
    }

    /**
     * 新增科研成果-期刊
     */
    @PreAuthorize("@ss.hasPermi('system:magazine:add')")
    @Log(title = "科研成果-期刊", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增科研成果-期刊", notes = "新增科研成果-期刊")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody MagazineDTO dto) {
        String result = magazineService.add(dto);
        return StringUtils.isNotEmpty(result) ? success((Object) result) : error();
    }

    /**
     * 修改科研成果-期刊
     */
    @PreAuthorize("@ss.hasPermi('system:magazine:edit')")
    @Log(title = "科研成果-期刊", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改期刊", notes = "修改期刊")
    @PostMapping(value = "/update")
    public AjaxResult edit(@RequestBody MagazineDTO dto) {
        return toAjax(magazineService.update(dto));
    }

    /**
     * 删除科研成果-期刊
     */
    @PreAuthorize("@ss.hasPermi('system:magazine:remove')")
    @Log(title = "科研成果-期刊", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除期刊", notes = "删除期刊")
    @DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids) {
        return toAjax(magazineService.batchRemove(ids));
    }
}
